﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using JVP.Gateway;
using System.Data.SqlClient;
using System.Collections;

namespace JeevanVaisya
{
    public partial class AdminHome : Form
    {
        #region Initializers
        Gateway gateway = new Gateway();
        int i = 0;// To avoid the lstPlan_SelectedValueChanged() Event while list item is created
        string user;
        string Status;
        #endregion

        #region Admin Home Constructor
        /// <summary>
        /// Constructor for the Admin Home Class.
        /// </summary>
        public AdminHome(string userName)
        {
            InitializeComponent();
            //Main Form Event
            Load += new EventHandler(AdminHome_Load);
            
            //Plan Tab Events
            tabPlan.Enter += new EventHandler(tabPlan_Enter);
            lstPlan.SelectedValueChanged += new EventHandler(lstPlan_SelectedValueChanged);
            cbPlanType.Text = "Select Plan Type";
            cbPlanType.Items.Add("Renewal");
            cbPlanType.Items.Add("Lump Sum");
            cbPlanType.Items.Add("Lump Sum (C)");

            
            //Scheme Tab Events
            txtInstall.Leave += new EventHandler(txtInstall_Leave);            
            txtInstall.GotFocus += new EventHandler(txtInstall_GotFocus);            
            txtConsi.Leave += new EventHandler(txtConsi_Leave);
            txtConsi.GotFocus += new EventHandler(txtConsi_GotFocus);
            txtExpConsi.Leave += new EventHandler(txtExpConsi_Leave);
            txtExpConsi.GotFocus += new EventHandler(txtExpConsi_GotFocus);
            txtAccConsi.Leave += new EventHandler(txtAccConsi_Leave);
            txtAccConsi.GotFocus += new EventHandler(txtAccConsi_GotFocus);            
            tabScheme.Enter += new EventHandler(tabScheme_Enter);
            btnSchSave.Click += new EventHandler(btnSchSave_Click);
            btnSchCancel.Click += new EventHandler(btnSchCancel_Click);
            dgvScheme.SelectionChanged += new EventHandler(dgvScheme_SelectionChanged);
            
            
            //Branch Tab Events
            btnBrnSave.Click += new EventHandler(btnBrnSave_Click);            
            tabBranch.Enter+=new EventHandler(tabBranch_Enter);
            btnBrnCancel.Click += new EventHandler(btnBrnCancel_Click);
            lstBranch.SelectedValueChanged += new EventHandler(lstBranch_SelectedValueChanged);
            
            //Additional Features
            lnkPassword.Click += new EventHandler(lnkPassword_Click);
            lnkDownLine.Click += new EventHandler(lnkDownLine_Click);
            
            //Employee Account Event
            tabEmployee.Enter += new EventHandler(tabEmployee_Enter);
            btnCreate.Click += new EventHandler(btnCreate_Click);
            btnEACancel.Click += new EventHandler(btnEACancel_Click);
            chkBlock.CheckedChanged += new EventHandler(chkBlock_CheckedChanged);
            chkUnBlock.CheckedChanged += new EventHandler(chkUnBlock_CheckedChanged);

            //Designation Details Events
            btnDesSave.Click += new EventHandler(btnDesSave_Click);
            btnDesCancel.Click += new EventHandler(btnDesCancel_Click);
            dgDesignation.SelectionChanged += new EventHandler(dgDesignation_SelectionChanged);
            tabDesignation.Enter += new EventHandler(tabDesignation_Enter);
            
            user = userName;
        }

        #endregion

        #region Scheme Tab Enters

        void tabScheme_Enter(object sender, EventArgs e)
        {
            //To set the progress value as minimum value.
            if (stsProgress.Value == stsProgress.Maximum)
                stsProgress.Value = stsProgress.Minimum;
            //To enable the progress bar process.
            tmrProgress.Enabled = true;
            dgvScheme.DataSource = null;
            rbtnSchActive.Checked = true;
        }

        #endregion

        #region Change Text to Currency
        
        /// <summary>
        /// To change text to currency and select all the text when focusing text boxes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        
        void txtAccConsi_GotFocus(object sender, EventArgs e)
        {
            txtAccConsi.SelectAll();
        }

        void txtAccConsi_Leave(object sender, EventArgs e)
        {
            if (txtAccConsi.Text == "") txtAccConsi.Text = "0.00"; 
            txtAccConsi.Text = String.Format("{0:c}", Convert.ToDecimal(txtAccConsi.Text));            
        }

        void txtExpConsi_GotFocus(object sender, EventArgs e)
        {
            txtExpConsi.SelectAll();
        }

        void txtExpConsi_Leave(object sender, EventArgs e)
        {
            if (txtExpConsi.Text == "") txtExpConsi.Text = "0.00"; 
            txtExpConsi.Text = String.Format("{0:c}", Convert.ToDecimal(txtExpConsi.Text));
        }

        void txtConsi_GotFocus(object sender, EventArgs e)
        {
            txtConsi.SelectAll();
        }

        void txtConsi_Leave(object sender, EventArgs e)
        {
            if (txtConsi.Text == "") txtConsi.Text = "0.00";
            txtConsi.Text = String.Format("{0:c}", Convert.ToDecimal(txtConsi.Text));
        }
                
        void txtInstall_GotFocus(object sender, EventArgs e)
        {
            txtInstall.SelectAll();
        }

        void txtInstall_Leave(object sender, EventArgs e)
        {
            if (txtInstall.Text == "") txtInstall.Text = "0.00";
            txtInstall.Text = String.Format("{0:c}", Convert.ToDecimal(txtInstall.Text));
        }
        #endregion
        
        #region Enable Edit Item
        /// <summary>
        /// To Set the values into the text boxes
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void lstPlan_SelectedValueChanged(object sender, EventArgs e)
        {
            if (i != 1)
            {
                if (lstPlan.SelectedIndex != -1)
                {
                    SqlDataReader dr=gateway.getPlan(lstPlan.SelectedValue.ToString());
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            txtPlanName.Text = dr["PlanName"].ToString();
                            txtPlanTerm.Text = dr["PlanTerm"].ToString();
                            cbPlanType.Text = dr["PlanType"].ToString();
                            txtDescription.Text = dr["Description"].ToString();
                            if (dr["PlanStatus"].ToString() == "Active")
                                rbtnActive.Checked = true;
                            else
                                rbtnInactive.Checked = true;
                        }
                        lstPlan.Enabled = false;
                        btnSave.Text = "Edit";
                    }
                }
            }
        }
        #endregion

        #region Plan Tab Enters
        /// <summary>
        /// To get the available plans from database and store into the list box
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void tabPlan_Enter(object sender, EventArgs e)
        {
                //To set the progress value as minimum value.
                if (stsProgress.Value == stsProgress.Maximum)
                    stsProgress.Value = stsProgress.Minimum;
                //To enable the progress bar process.
                tmrProgress.Enabled = true;
                rbtnActive.Checked = true;           
        }
        #endregion

        #region AdmiHome Page Load
        /// <summary>
        /// To function trigger while admin page loaded
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void AdminHome_Load(object sender, EventArgs e)
        {
            imgLoding.Visible = true;
            tabPlan_Enter(sender, e);
            stsUserName.Text = "Welcome " + user;
            dateTime.Enabled = true;
            stsTime.Text = "Login Time : " + DateTime.Now.ToLongTimeString();
        }
        #endregion

        #region Plan Save or Edit
        /// <summary>
        /// To Save or Edit the Plan Details into the database
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>

        private void btnSave_Click(object sender, EventArgs e)
        {
            try
            {                
                tmrProgress.Enabled = true;                
                if (txtPlanName.Text != "" && txtPlanTerm.Text != "" &&  cbPlanType.Text!="Select Plan Type")
                {
                    if (rbtnActive.Checked)
                        Status = rbtnActive.Text;
                    else
                        Status = rbtnInactive.Text;

                    if (btnSave.Text == "Save")
                    {
                        if (gateway.addPlan(txtPlanName.Text, txtPlanTerm.Text, cbPlanType.Text, Status, txtDescription.Text))
                        {
                            MessageBox.Show("New Plan Added Sucessfully");
                            tabPlan_Enter(sender, e);
                            clearing();
                        }
                    }
                    else
                    {
                        if (gateway.editPlan(lstPlan.SelectedValue.ToString(), txtPlanName.Text, txtPlanTerm.Text, cbPlanType.Text, Status, txtDescription.Text))
                        {
                            MessageBox.Show("Plan Edited Sucessfully");
                            tabPlan_Enter(sender, e);
                            clearing();
                            lstPlan.Enabled = true;                            
                        }
                    }
                }
                else                
                    MessageBox.Show("Please Enter Plan Name & Plan Term");
            }
            catch(Exception er)
            {
                MessageBox.Show(er.ToString());
            }
        }
        #endregion

        #region Scheme Save & Edit Event

        void btnSchSave_Click(object sender, EventArgs e)
        {
            tmrProgress.Enabled=true;
            try
            {
                if (txtYear.Text != "" && txtMonth.Text != "" && txtConsi.Text != "" && txtExpConsi.Text != "" && txtPlotSize.Text != "" && cbPlan.Text != "Select Plan")
                {
                    if (rbtnSchActive.Checked)
                        Status = rbtnSchActive.Text;
                    else
                        Status = rbtnSchInactive.Text;

                    if (btnSchSave.Text == "Save")
                    {
                        if (gateway.addScheme(Convert.ToInt32(txtDues.Text), txtYear.Text + lblY.Text + " - " + txtMonth.Text + lblM.Text, String.Format("{0:c}", Convert.ToDecimal(txtInstall.Text)), txtConsi.Text, txtExpConsi.Text, txtAccConsi.Text, txtPlotSize.Text, Status, cbPlan.SelectedValue.ToString()))
                        {                            
                            tabScheme_Enter(sender, e);
                            MessageBox.Show("New Scheme Added Successfully");
                        }
                    }
                    else
                    {
                        if (gateway.editScheme(dgvScheme.SelectedRows[0].Cells["SchemeID"].Value.ToString(), Convert.ToInt32(txtDues.Text), txtYear.Text + lblY.Text + " - " + txtMonth.Text + lblM.Text, String.Format("{0:c}", Convert.ToDecimal(txtInstall.Text)), txtConsi.Text, txtExpConsi.Text, txtAccConsi.Text, txtPlotSize.Text, Status, cbPlan.SelectedValue.ToString()))
                        {                            
                            tabScheme_Enter(sender, e);
                            MessageBox.Show("Scheme Edited Successfully");
                        }
                    }
                }
                else
                {
                    MessageBox.Show("Enter All Values");
                }
            }
            catch (Exception er)
            {
                MessageBox.Show(er.ToString());
            }
        }

        #endregion

        #region Cancel Event
        /// <summary>
        /// To Cancel the current action
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            clearing();
            if (lstPlan.Enabled == false && lstPlan.Items[0].ToString() != "No Plans Available")
                lstPlan.Enabled = true;
        }
        #endregion

        #region Scheme Cancel Event

        void btnSchCancel_Click(object sender, EventArgs e)
        {
            clearing();            
        }
        #endregion

        #region DataGridView Scheme Selection Changed Event

        void dgvScheme_SelectionChanged(object sender, EventArgs e)
        {
            if (i != 1)
            {
                try
                {
                    cbPlan.SelectedIndex = -1;
                    cbPlan.SelectedIndex = Convert.ToInt32(dgvScheme.SelectedRows[0].Cells["PlanID"].Value.ToString()) - 1;
                    txtDues.Text = dgvScheme.SelectedRows[0].Cells["SchemeDues"].Value.ToString();
                    txtYear.Text = dgvScheme.SelectedRows[0].Cells["PlanYear"].Value.ToString().Substring(0, dgvScheme.SelectedRows[0].Cells["PlanYear"].Value.ToString().IndexOf("Y"));
                    int val1 = (dgvScheme.SelectedRows[0].Cells["PlanYear"].Value.ToString().IndexOf("-") + 2);
                    int val2 = dgvScheme.SelectedRows[0].Cells["PlanYear"].Value.ToString().Length - dgvScheme.SelectedRows[0].Cells["PlanYear"].Value.ToString().IndexOf("M");
                    txtMonth.Text = dgvScheme.SelectedRows[0].Cells["PlanYear"].Value.ToString().Substring(val1, val2);
                    txtInstall.Text = dgvScheme.SelectedRows[0].Cells["Amount"].Value.ToString();
                    txtConsi.Text = dgvScheme.SelectedRows[0].Cells["Consideration"].Value.ToString();
                    txtExpConsi.Text = dgvScheme.SelectedRows[0].Cells["ExpConsideration"].Value.ToString();
                    txtAccConsi.Text = dgvScheme.SelectedRows[0].Cells["AccConsideration"].Value.ToString();
                    txtPlotSize.Text = dgvScheme.SelectedRows[0].Cells["PlotSize"].Value.ToString();
                    if (dgvScheme.SelectedRows[0].Cells["Status"].Value.ToString() == "Active")
                        rbtnSchActive.Checked = true;
                    else
                        rbtnSchInactive.Checked = true;
                    dgvScheme.Enabled = false;
                    btnSchSave.Text = "Edit";
                }
                catch (Exception er){}
            }
        }

        #endregion

        #region Clearing
        /// <summary>
        /// To Clear the Text box value and Set the Save Button text as Empty in Plan Tab.
        /// </summary>
        private void clearing()
        {
            if (tabPlan.Focus())
            {
                txtPlanName.Text = "";
                txtPlanTerm.Text = "";
                txtDescription.Text = "";
                cbPlanType.Text = "Select Plan Type";
                btnSave.Text = "Save";
            }
            else if (tabScheme.Focus())
            {
                txtDues.Text = "0";
                txtYear.Text = "0";
                txtMonth.Text = "0";
                txtInstall.Text = "0.00";
                txtConsi.Text = "0.00";
                txtExpConsi.Text = "0.00";
                txtAccConsi.Text = "0.00";
                txtPlotSize.Text = "0";
                cbPlan.Text = "Select Plan";
                btnSchSave.Text = "Save";                
                dgvScheme.Enabled = true;
            }
            else if (tabBranch.Focus())
            {
                txtBranchName.Text = "";
                txtBranchCode.Text = "";
                txtBranchCity.Text = "";
                txtBranchCCode.Text = "";
                btnBrnSave.Text = "Save";
            }
            else if (tabDesignation.Focus())
            {
                txtDesignation.Text = "";
                numRank.Value = 0;
                numIYear.Value = 0;
                numIIYear.Value = 0;
                numIIIYear.Value = 0;
                numLumpSum.Value = 0;
                btnDesSave.Text = "Save";
                dgDesignation.Enabled = true;
            }            
            else
            {
                txtFName.Text = "";
                txtLName.Text = "";
                txtPhone.Text = "";
                txtAddress.Text = "";
                cbBranch.Text = "Select Branch";
                dpDOB.Value = DateTime.Now;
            }
        }        
        #endregion

        #region Enable Date & Time Timer
        /// <summary>
        /// To enable the date and time in status bar
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dateTime_Tick(object sender, EventArgs e)
        {
            stsDate.Text = DateTime.Now.ToString();
        }
        #endregion

        #region Progress Timer
        /// <summary>
        /// To enable the progress bar
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void tmrProgress_Tick(object sender, EventArgs e)
        {
            mainPanel.Enabled = false;
            stsStatus.Text = "Status : Wait";
            stsProgress.PerformStep();
            if(stsProgress.Value == stsProgress.Maximum)
            {
                tmrProgress.Enabled = false;
                stsProgress.Value = stsProgress.Minimum;
                mainPanel.Enabled = true;                
                getPlan();
                clearing();
            }
        }
        #endregion

        #region Get Plan or Scheme or Branch
        /// <summary>
        /// To get the plans from database.
        /// </summary>
        private void getPlan()
        {
            stsStatus.Text = "Status : Ready";
            SqlDataReader dr = null;
            SqlDataAdapter da = null;
            //To make the list box empty
            lstBranch.DataSource = null;
            lstPlan.DataSource = null;
            if (tabPlan.Focus() || tabScheme.Focus())
            {
                dr = gateway.getAllPlans();                
                if (dr.HasRows)
                {
                    ArrayList PlanDetails = new ArrayList();                    
                    while (dr.Read())
                        PlanDetails.Add(new GeneralDataTypes(dr["PlanName"].ToString() + " - " + dr["PlanTerm"].ToString(), dr["PlanID"].ToString()));
                    i = 1;
                    if (tabPlan.Focus())
                    {
                        //To add the plans into list box in plan details tab
                        lstPlan.DataSource = PlanDetails;
                        lstPlan.DisplayMember = "PlanName";
                        lstPlan.ValueMember = "PlanID";
                        txtPlanName.Focus();
                    }
                    else
                    {
                        // To Add the Plans into combo box in scheme details tab
                        cbPlan.DataSource = PlanDetails;
                        cbPlan.DisplayMember = "PlanName";
                        cbPlan.ValueMember = "PlanID";
                        cbPlan.Text = "Select Plan";
                        //To add schemes into the data grid view
                        da = gateway.getSchemes();
                        DataSet ds = new DataSet();
                        da.Fill(ds, "SchemeDetails");
                        da.Dispose();
                        dgvScheme.DataSource = null;
                        dgvScheme.DataSource = ds.Tables["SchemeDetails"];
                        dgvScheme.ReadOnly = true;
                        dgvScheme.MultiSelect = false;
                        dgvScheme.Columns["SchemeID"].Visible = false;
                        dgvScheme.Columns[1].HeaderText = "Dues";
                        dgvScheme.Columns[2].HeaderText = "Duration";
                        dgvScheme.Columns[3].HeaderText = "Installment";
                        dgvScheme.Columns[4].HeaderText = "Consi.";
                        dgvScheme.Columns[5].HeaderText = "Exp. Consi.";
                        dgvScheme.Columns[6].HeaderText = "Acc. Consi.";
                        dgvScheme.Columns[7].HeaderText = "Plot Size";
                        dgvScheme.Columns["PlanID"].Visible = false;
                        dgvScheme.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray;                        
                    }
                }
                else
                {
                    lstPlan.Items.Add("No Plans Available");
                    lstPlan.Enabled = false;
                }
            }
            else if (tabBranch.Focus() || tabEmployee.Focus())
            {
                //To Add the items into the list box lstBranch in Branch Tab.
                dr = gateway.getBranches();
                if (dr.HasRows)
                {
                    ArrayList BranchDetails = new ArrayList();
                    if (tabBranch.Focus())
                    {
                        while (dr.Read())
                            BranchDetails.Add(new GeneralDataTypes(dr["BranchName"].ToString() + " - " + dr["BranchCode"].ToString() + " - " + dr["BranchCity"].ToString(), Convert.ToInt32(dr["BranchID"].ToString())));
                        i = 1;
                        lstBranch.DataSource = BranchDetails;
                        lstBranch.DisplayMember = "BranchName";
                        lstBranch.ValueMember = "BranchCode";
                    }
                    else
                    {
                        while (dr.Read())
                            BranchDetails.Add(new GeneralDataTypes(dr["BranchCity"].ToString(), Convert.ToInt32(dr["BranchID"].ToString())));
                        i = 1;                        
                        cbBranch.DataSource = BranchDetails;
                        cbBranch.DisplayMember = "BranchName";
                        cbBranch.ValueMember = "BranchCode";
                        cbBranch.Text = "Select Branch";
                    }

                }
                else
                {
                    lstBranch.Items.Add("No Branches Available");
                    lstBranch.Enabled = false;
                }
            }
            else if (tabDesignation.Focus())
            {
                i = 1;
                da = gateway.getDesignations();
                DataSet ds = new DataSet();
                da.Fill(ds, "DesignationDetails");
                da.Dispose();
                dgDesignation.DataSource = null;
                dgDesignation.DataSource = ds.Tables["DesignationDetails"];
                dgDesignation.MultiSelect = false;
                dgDesignation.Columns["DesignationCode"].Visible = false;
                dgDesignation.Columns["DesignationName"].HeaderText = "Designation";
                dgDesignation.Columns["IYear"].HeaderText="I Yr.";
                dgDesignation.Columns["IIYear"].HeaderText="II Yr.";
                dgDesignation.Columns["IIIYear"].HeaderText="III Yr.";
                dgDesignation.Columns["LumpSum"].HeaderText="Lump Sum";                
                dgDesignation.ReadOnly = true;
                dgDesignation.AlternatingRowsDefaultCellStyle.BackColor = Color.LightGray;               
            }
            i = 0;
            if (dr != null)
            {
                dr.Close();
                dr.Dispose();
            }
        }
        #endregion

        #region Branch Details

        void lstBranch_SelectedValueChanged(object sender, EventArgs e)
        {
            if (i != 1)
            {
                if (lstBranch.SelectedIndex != -1)
                {
                    SqlDataReader dr = gateway.getBranch(lstBranch.SelectedValue.ToString());
                    if (dr.HasRows)
                    {
                        while (dr.Read())
                        {
                            txtBranchCode.Text = dr["BranchCode"].ToString();
                            txtBranchName.Text = dr["BranchName"].ToString();
                            txtBranchCity.Text = dr["BranchCity"].ToString();
                            txtBranchCCode.Text = dr["BranchCityCode"].ToString();
                        }
                        lstBranch.Enabled = false;
                        btnBrnSave.Text = "Edit";
                    }
                }
            }
        }        

        void btnBrnCancel_Click(object sender, EventArgs e)
        {
            clearing();
            if (lstBranch.Enabled == false && lstBranch.Items[0].ToString() != "No Branches Available")
                lstBranch.Enabled = true;
        }

        void tabBranch_Enter(object sender, EventArgs e)
        {
                //To set the progress value as minimum value.
                if (stsProgress.Value == stsProgress.Maximum)
                    stsProgress.Value = stsProgress.Minimum;
                //To enable the progress bar process.
                tmrProgress.Enabled = true;
        }

        void btnBrnSave_Click(object sender, EventArgs e)
        {
            try
            {
                tmrProgress.Enabled = true;
                if (txtBranchName.Text != "" && txtBranchCode.Text != "" && txtBranchCity.Text != "" && txtBranchCCode.Text != "")
                {
                    if (btnBrnSave.Text == "Save")
                    {
                        if (gateway.addBranch(txtBranchCode.Text,txtBranchName.Text,txtBranchCity.Text,txtBranchCCode.Text))
                        {
                            MessageBox.Show("New Branch Added Sucessfully");
                            tabBranch_Enter(sender, e);
                            clearing();
                        }
                    }
                    else
                    {
                        //if (gateway.editPlan(lstPlan.SelectedValue.ToString(), txtPlanName.Text, txtPlanTerm.Text, cbPlanType.SelectedText, txtDescription.Text))
                        //{
                        //    MessageBox.Show("Branch Edited Sucessfully");
                        //    tabBranch_Enter(sender, e);
                        //    clearing();
                        //    lstBranch.Enabled = true;
                        //}
                    }
                }
                else
                    MessageBox.Show("Please Enter Branch Details");
            }
            catch (Exception er)
            {
                MessageBox.Show(er.ToString());
            }
        }

        #endregion

        #region Addition Features
                

        void lnkPassword_Click(object sender, EventArgs e)
        {
            ChangePassword changePassword = new ChangePassword(user);
            changePassword.ShowDialog();
        }

        
        void lnkDownLine_Click(object sender, EventArgs e)
        {
            DownLine downLine = new DownLine();
            downLine.ShowDialog();
        }


        #endregion
        
        #region Employee Account

        void btnEACancel_Click(object sender, EventArgs e)
        {
            clearing();
        }

        void btnCreate_Click(object sender, EventArgs e)
        {
            if (txtFName.Text != "" && dpDOB.Value.ToShortDateString() != DateTime.Now.ToShortDateString() && txtAddress.Text != "" && cbBranch.Text != "Select Branch")
            {
                if (chkUnBlock.Checked)
                    Status = chkUnBlock.Text;
                else
                    Status = chkBlock.Text;
                if (gateway.createAccount(txtFName.Text,txtLName.Text,dpDOB.Value,txtAddress.Text,txtPhone.Text,Status,Convert.ToInt32(cbBranch.SelectedValue)))
                {
                    MessageBox.Show("Account Created Successfully");
                    clearing();                    
                }
            }
            else
                MessageBox.Show("Enter All Fields");
        }

        void tabEmployee_Enter(object sender, EventArgs e)
        {
            //To set the progress value as minimum value.
            if (stsProgress.Value == stsProgress.Maximum)
                stsProgress.Value = stsProgress.Minimum;
            //To enable the progress bar process.
            tmrProgress.Enabled = true;
            chkUnBlock.Checked = true;
        }

        void chkBlock_CheckedChanged(object sender, EventArgs e)
        {
            if (chkBlock.Checked && chkUnBlock.Checked)
                chkUnBlock.Checked = false;
        }

        void chkUnBlock_CheckedChanged(object sender, EventArgs e)
        {
            if (chkBlock.Checked && chkUnBlock.Checked)
                chkBlock.Checked = false;
        }

        #endregion

        #region Designation Details

        void btnDesCancel_Click(object sender, EventArgs e)
        {
            clearing();
        }

        void btnDesSave_Click(object sender, EventArgs e)
        {
            if (txtDesignation.Text != "")
            {
                if (btnDesSave.Text == "Save")
                {
                    if (gateway.addDesignation(txtDesignation.Text, (int)numRank.Value, numIYear.Value, numIIYear.Value, numIIIYear.Value, numLumpSum.Value))
                        MessageBox.Show("New Designation Added Successfully");
                }
                else
                {
                    if (gateway.editDesignation(Convert.ToInt32(dgDesignation.SelectedRows[0].Cells["DesignationCode"].Value.ToString()), txtDesignation.Text, (int)numRank.Value, numIYear.Value, numIIYear.Value, numIIIYear.Value, numLumpSum.Value))
                        MessageBox.Show("Designation Edited Successfully");
                }
                dgDesignation.DataSource = null;
                tabDesignation_Enter(sender, e);                    
            }
            else
                MessageBox.Show("Enter All Fields");
        }
        
        void dgDesignation_SelectionChanged(object sender, EventArgs e)
        {
            if (i != 1)
            {
                try
                {
                    txtDesignation.Text = dgDesignation.SelectedRows[0].Cells["DesignationName"].Value.ToString();
                    numRank.Value = Convert.ToDecimal(dgDesignation.SelectedRows[0].Cells["Rank"].Value.ToString());
                    numIYear.Value = Convert.ToDecimal(dgDesignation.SelectedRows[0].Cells["IYear"].Value.ToString());
                    numIIYear.Value = Convert.ToDecimal(dgDesignation.SelectedRows[0].Cells["IIYear"].Value.ToString());
                    numIIIYear.Value = Convert.ToDecimal(dgDesignation.SelectedRows[0].Cells["IIIYear"].Value.ToString());
                    numLumpSum.Value = Convert.ToDecimal(dgDesignation.SelectedRows[0].Cells["LumpSum"].Value.ToString());
                    dgDesignation.Enabled = false;
                    btnDesSave.Text = "Edit";                    
                }
                catch (Exception er) { }
            }
        }

        void tabDesignation_Enter(object sender, EventArgs e)
        {
            if (stsProgress.Value == stsProgress.Maximum)
                stsProgress.Value = stsProgress.Minimum;
            if(dgDesignation.DataSource==null)
                tmrProgress.Enabled = true;
        }

        #endregion
    }
}
